/** ***************************************************************************
 * CoffeeMath.hpp
 * 2012 CoffeeParty Ltd.
 * Date Created: 2012-07-21                                  format YYYY-MM-DD
 * Revision Id: $Id$
 ******************************************************************************
 */

#ifndef _COFFEE_MATH_HPP_
#define _COFFEE_MATH_HPP_

template<class T>
inline const T& c_min(const T& a, const T& b)
{
    return (a < b ? a : b);
}

template<class T>
inline const T& c_max(const T& a, const T& b)
{
    return (a < b ? b : a);
}

template<class T>
inline T c_abs(const T& a)
{
    return (a < (T)0 ? -a : a);
}

template<class T>
inline T c_lerp(const T& a, const T& b, const float t)
{
    return (T)(a * (1.0f - t)) + (b * t);
}

template<class T>
inline const T c_clamp(const T& value, const T& low, const T& high)
{
    return c_min(c_max(value, low), high);
}

template<class T1, class T2>
inline void c_swap(T1& a, T2& b)
{
    T1 c(a);
    a = b;
    b = c;
}

#endif /** _COFFEE_MATH_HPP_ */
